<?php
session_start();
include_once '../thumb_class.php';
//if ((!empty($_FILES))&&($_SESSION['username'] != '')) {
	$tempFile = $_FILES['Filedata']['tmp_name'];
	if($_REQUEST['lang'] == 'tc'){
		$tempFile_2 = "../../upload/index_img/tc/tmp/".$_FILES['Filedata']['name'];
		$targetFile =  str_replace('//','/',$_SERVER['DOCUMENT_ROOT'].'/upload/index_img/tc/tmp/') . $_FILES['Filedata']['name'];
		move_uploaded_file($tempFile,$targetFile);
		list($width, $height, $type, $attr) = getimagesize($tempFile_2);
		if(($width%340)&&($height%90)){
			unlink($tempFile_2);
			echo "sizeerror";
			die();
		}
		$big = "../../upload/index_img/tc/big/".$_FILES['Filedata']['name'];
		$small = "../../upload/index_img/tc/small/".$_FILES['Filedata']['name'];
		try {
			$obj = new ThumbHandler();
			$obj->setSrcImg($tempFile_2);
			$obj->setDstImg($big);
			$obj->createImg(340, 90);
			$obj_2 = new ThumbHandler();
			$obj_2->setSrcImg($tempFile_2);
			$obj_2->setDstImg($small);
			$obj_2->createImg(340, 114);
		}
		catch (Exception $e) {
			die($e);
		}
		echo "success";
	}else{
		$tempFile_2 = "../../upload/index_img/sc/tmp/".$_FILES['Filedata']['name'];
		$targetFile =  str_replace('//','/',$_SERVER['DOCUMENT_ROOT'].'/upload/index_img/sc/tmp/') . $_FILES['Filedata']['name'];
		move_uploaded_file($tempFile,$targetFile);
		list($width, $height, $type, $attr) = getimagesize($tempFile_2);
		if(($width%340)&&($height%90)){
			unlink($tempFile_2);
			echo "sizeerror";
			die();
		}
		$big = "../../upload/index_img/sc/big/".$_FILES['Filedata']['name'];
		$small = "../../upload/index_img/sc/small/".$_FILES['Filedata']['name'];
		try {
			$obj = new ThumbHandler();
			$obj->setSrcImg($tempFile_2);
			$obj->setDstImg($big);
			$obj->createImg(340, 90);
			$obj_2 = new ThumbHandler();
			$obj_2->setSrcImg($tempFile_2);
			$obj_2->setDstImg($small);
			$obj_2->createImg(340, 114);
		}
		catch (Exception $e) {
			die($e);
		}
		echo "success";
	}
	
	// } else {
	// 	echo 'Invalid file type.';
	// }
//}
?>